import got from "got";
import cheerio from 'cheerio';
import { Article } from "../types/article";
import { writeFileByType } from "./util";

const downArticle = async (item: Article) => {
  const url = `https://juejin.im/post/${item.id}`;
  const res = await got.post(url);
  const body = res.body;
  const $ = cheerio.load(body);
  const html = $('.markdown-body').html()?.toString() || ''
  item.html = html
  if (html) {
    writeFileByType(`juejin/${item.id}`, item, 'json');
  }
};

export { downArticle };
